package pri.zxx.webdemo.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author zxx
 * @desc 加载jar包中的文件
 * @createTime 2019-11-13-上午 9:34
 */
@Service
@Slf4j
public class ReadFileTest {


//    @PostConstruct
    public void readResource() throws IOException {
        ClassPathResource cpr = new ClassPathResource("classpath:files/shiro.txt");
        FileInputStream fileInputStream = new FileInputStream(cpr.getFile());
        FileChannel channel = fileInputStream.getChannel();
        ByteBuffer allocate = ByteBuffer.allocate(fileInputStream.available());
        channel.read(allocate);
        System.out.println(new String(allocate.array()));
        channel.close();
        fileInputStream.close();
    }
}
